package com.example.blog.config;

import com.example.blog.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-01-08
 * Time: 12:57
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    private final List excludes = Arrays.asList(
            "/**/*.html",            // 所有的 HTML 页面
            "/blog-editormd/**",     // 编辑器的路径
            "/css/**",               // 静态资源 CSS
            "/js/**",                // 静态资源 JS
            "/pic/**",               // 图片资源
            "/user/login",            // 登录页面路径
            "/static/favicon.ico",
            "/favicon.ico"
    );//这些路径下不拦截

    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(loginInterceptor)//注册一个拦截器
                .addPathPatterns("/**")
                .excludePathPatterns(excludes);//不拦截哪些路径
    }
}
